//
//  SEChatCheckReportCell.swift
//  SmartEyeForPatient
//
//  Created by QDSG on 2021/6/10.
//

import UIKit

class SEChatCheckReportCell: UITableViewCell {

    override func setHighlighted(_ highlighted: Bool, animated: Bool) {
        super.setHighlighted(highlighted, animated: animated)
        containerView.backgroundColor = highlighted ? Asset.main.color.withAlphaComponent(0.25) : Asset.white.color
    }
    
    func update(with viewModel: SEChatViewModel) {
        nameLabel.text = viewModel.checkReport?.name
        timeLabel.text = viewModel.checkReport?.time
        
        collectionView.titles = viewModel.checkReport?.list ?? []

        layoutIfNeeded()
        collectionView.reloadData()
        let contentSize = collectionView.collectionViewLayout.collectionViewContentSize
        collectionViewHeightConstraint.constant = contentSize.height
        containerViewHeightConstraint.constant =  77 + contentSize.height
    }
    
    @IBOutlet private weak var containerView: UIView! {
        didSet {
            containerView.layer.cornerRadius = 6
            containerView.layer.borderColor = UIColor(hex: "#EBEBEB").cgColor
            containerView.layer.borderWidth = 1
            containerView.layer.masksToBounds = true
        }
    }
    
    @IBOutlet private weak var nameLabel: UILabel!
    @IBOutlet private weak var timeLabel: UILabel!
    @IBOutlet private weak var collectionView: SETagsCollectionView!
    @IBOutlet var collectionViewHeightConstraint: NSLayoutConstraint!
    @IBOutlet var containerViewHeightConstraint: NSLayoutConstraint!

}
